<?php
namespace app\app\model;
use think\Model;
use think\Db;

class FightModel extends Model{

    public $user_id;
    protected $table = "a_fight";

    public function getFight(){
        //对战次数
        $count = $this->where('user_id','eq',$this->user_id)->count();
        //对战好友数
        $friend = $count;
        //胜场
        $win  = $this->where('user_id','eq',$this->user_id)->where('result','eq',1)->count();
        //胜率
        if($count && $count != 0){
            $rate = ($win/$count)*100;
            $rate = ceil($rate);
        }else{
            $rate = "0";
        }
        $arr = array('total_fight'=>$count,'friend'=>$friend,'win'=>$win,'rate'=>$rate."%");
        return $arr;
    }

}